<template>
  <div class="login_container">
    <el-card class="login_card" header="请先登录">
      <el-form>
        <i class="el-icon-user-solid"></i>
        <el-form-item icon="el-icon-user-solid">
          <el-input v-model="model.username"></el-input>
        </el-form-item>
        <i class="el-icon-s-goods"></i>
        <el-form-item>
          <el-input v-model="model.password" type="password"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" style="margin-left:42%" @click="login">登录</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>
<script>
export default {
  name: 'Login',
  data() {
    return {
      model: {}
    }
  },
  methods: {
    async login() {
      const res = await this.$http.post('login', this.model)
      if (res.status !== 200) {
        return
      }
      sessionStorage.setItem('token', res.data)
      this.$router.push('/welcome')
    }
  }
}
</script>

<style  scoped>
.login_container {
  width: 30rem;
  margin: 5rem auto;
}
</style>

